<%@ page import="cn.gudian.cms.News.ArcType; cn.gudian.cms.Admin.AuthSession; cn.gudian.cms.News.Article" %>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  <meta name="layout" content="main"/>
  <title><g:message code="article.create" default="Create Article"/></title>
  <script src="/js/jquery.min.js" type="text/javascript"></script>
  <script type="text/javascript">
    $(document).ready(function () {
      $("#advanced").hide();
      $("#advancedMenu").click(function() {
        $("#advanced").slideToggle()
      })

      var imgHtmlInit = "";
    <g:if test="${articleInstance?.thumbnails}">
      imgHtmlInit += getImgItemHtml('${articleInstance?.thumbnails}', '96', "缩略图");
    </g:if>
      $("#upload-gallery-1").html(imgHtmlInit);

    });
    function imgUploadSucceed(name, path, w, h) {
      $("#thumbnails").val(path)
      var imgHtml = "";
      imgHtml += getImgItemHtml(path, '96', "缩略图");
      $("#upload-gallery-1").html(imgHtml);
    }
    function imgCropSucceed(path) {
      $("#thumbnails").val(path)
      var imgHtml = "";
      imgHtml += getImgItemHtml(path, '96', "缩略图");
      $("#upload-gallery-1").html(imgHtml);
    }


    function getImgItemHtml(url, imgWidth, imgTxt) {
      return "<div class='item'>" +
              "<div class='pic'>" +
              "<a href='" + url + "' target='_blank' title='" + imgTxt + "'>" +
              "<img src='" + url + "' alt='" + imgTxt + "' width='" + imgWidth + "' />" +
              "</a></div>" +
              "<div class='txt'>" +
              "<h1>" + imgTxt + "</h1>" +
              "</div>" +
              "</div>";
    }
  </script>
  <ckeditor:resources/>
</head>
<body>
<div class="nav">
  <span class="menuButton"><a class="home" href="${createLinkTo(dir: '')}"><g:message code="home" default="Home"/></a></span>
  <span class="menuButton"><a href="/article/list?mode=${mode}"><g:message code="article.list" default="Article List"/></a></span>
</div>
<div class="body">
  <h1><g:message code="article.create" default="Create Article"/></h1>
  <g:if test="${flash.message}">
    <div class="message"><g:message code="${flash.message}" args="${flash.args}" default="${flash.defaultMessage}"/></div>
  </g:if>
  <g:hasErrors bean="${articleInstance}">
    <div class="errors">
      <g:renderErrors bean="${articleInstance}" as="list"/>
    </div>
  </g:hasErrors>
  <g:form action="save" method="post">
    <g:hiddenField name="mode" value="${mode}"/>

    <div class="dialog">
      <table>
        <tbody>

        <tr class="prop">
          <td valign="top" class="name">
            <label for="arcType"><g:message code="article.arcType" default="Arc Type"/>:</label>
          </td>
          <td valign="top" class="value ${hasErrors(bean: articleInstance, field: 'arcType', 'errors')}">

            <gd:arcTypeSelect nbsp="1" id="arcType.id" mode="${mode}" nowID="${articleInstance?.arcType?.id}"/>
          </td>
        </tr>

        <tr class="prop">
          <td valign="top" class="name">
            <label for="title"><g:message code="article.title" default="Title"/>:</label>
          </td>
          <td valign="top" class="value ${hasErrors(bean: articleInstance, field: 'title', 'errors')}">
            <g:textField name="title" value="${fieldValue(bean: articleInstance, field: 'title')}"/>

          </td>
        </tr>

        <tr class="prop">
          <td valign="top" class="name">
            <label for="body"><g:message code="article.body" default="Body"/>:</label>
          </td>
          <td valign="top" class="value ${hasErrors(bean: articleInstance, field: 'body', 'errors')}">

            <ckeditor:editor name="body">
              ${articleInstance?.body}
            </ckeditor:editor>
          </td>
        </tr>


        <tr><td height="30px" colspan="2" align="center" valign="middle" bgcolor="#CCCCCC" style="cursor:hand;" id="advancedMenu">高级选项</td></tr>
        <tr>
          <td colspan="2">

            <table id="advanced">
              <tr class="prop">
                <td valign="top" class="name">
                  <label for="thumbnails"><g:message code="article.thumbnails" default="Thumbnails"/>:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: articleInstance, field: 'thumbnails', 'errors')}">
                  <g:textField name="thumbnails" value="${fieldValue(bean: articleInstance, field: 'thumbnails')}"/>
                  <div id="upload-gallery-1"></div>
                  %{--<g:hiddenField name="thumbnails" value="${fieldValue(bean: articleInstance, field: 'thumbnails')}"/>--}%
                </td>
              </tr>
              <tr><td></td><td><iframe name="fileUpload" src="/share/imgUpload.gsp?${ArcType.getsize(mode)}" width="100%" height="50px;" frameborder="0" scrolling="no"></iframe></td></tr>
              <tr class="prop">
                <td valign="top" class="name">
                  <label for="url"><g:message code="article.url" default="Url"/>:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: articleInstance, field: 'url', 'errors')}">
                  <g:textField name="url" value="${fieldValue(bean: articleInstance, field: 'url')}"/>

                </td>
              </tr>
              <tr class="prop">
                <td valign="top" class="name">
                  <label for="shorttitle"><g:message code="article.shorttitle" default="Shorttitle"/>:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: articleInstance, field: 'shorttitle', 'errors')}">
                  <g:textField name="shorttitle" value="${fieldValue(bean: articleInstance, field: 'shorttitle')}"/>

                </td>
              </tr>
              <tr class="prop">
                <td valign="top" class="name">
                  <label for="writer"><g:message code="article.writer" default="Writer"/>:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: articleInstance, field: 'writer', 'errors')}">
                  <g:textField name="writer" value="${articleInstance.writer==null?AuthSession.getUser(session).getUserName():articleInstance.writer}"/>

                </td>
              </tr>

              <tr class="prop">
                <td valign="top" class="name">
                  <label for="orderNum"><g:message code="article.orderNum" default="Order Num"/>:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: articleInstance, field: 'orderNum', 'errors')}">
                  <g:textField name="orderNum" value="${fieldValue(bean: articleInstance, field: 'orderNum')}"/>

                </td>
              </tr>
              <tr class="prop">
                <td valign="top" class="name">
                  <label for="pubdate"><g:message code="article.pubdate" default="Pubdate"/>:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: articleInstance, field: 'pubdate', 'errors')}">

                  <gd:datePicker name="pubdate" value="${articleInstance?.pubdate}" precision="day"></gd:datePicker>
                </td>
              </tr>
              <tr class="prop">
                <td valign="top" class="name">
                  <label for="keywords"><g:message code="article.keywords" default="Keywords"/>:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: articleInstance, field: 'keywords', 'errors')}">
                  <g:textArea name="keywords" value="${fieldValue(bean: articleInstance, field: 'keywords')}" style="width:100%;height:50px;"/>

                </td>
              </tr>
              <tr class="prop">
                <td valign="top" class="name">
                  <label for="description"><g:message code="article.description" default="Description"/>:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: articleInstance, field: 'description', 'errors')}">
                  <ckeditor:editor name="description" height="100px" width="100%" toolbar="Simple">
                    ${articleInstance?.description}
                  </ckeditor:editor>

                </td>
              </tr>
              <tr class="prop">
                <td valign="top" class="name">
                  <label for="ispost"><g:message code="article.ispost" default="Ispost"/>:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: articleInstance, field: 'ispost', 'errors')}">

                  <g:checkBox name="ispost" value="${true}"/>

                </td>
              </tr>

            </table>

          </td>
        </tr>

        </tbody>
      </table>
    </div>
    <div class="buttons">
      <span class="button"><g:submitButton name="create" class="save" value="${message(code: 'create', 'default': 'Create')}"/></span>
    </div>
  </g:form>
</div>
</body>
</html>
